const isProduction = process.env.NODE_ENV === 'production'
const cdn = {
  css: [
    'https://cdn.bootcss.com/vuetify/2.0.5/vuetify.min.css',
  ],
  js: [
    'https://cdn.bootcss.com/vue-router/3.0.1/vue-router.min.js',
    'https://cdn.bootcss.com/vuex/3.0.1/vuex.min.js',
    'https://cdn.bootcss.com/axios/0.19.0/axios.min.js',
    'https://cdn.bootcss.com/vuetify/2.0.18/vuetify.min.js',
    'https://cdn.bootcss.com/js-cookie/2.2.0/js.cookie.min.js',
    'https://cdn.bootcss.com/sockjs-client/1.3.0/sockjs.min.js',
    'https://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js',
    'https://cdn.bootcss.com/exif-js/2.3.0/exif.min.js'
  ]
}
module.exports = {
  publicPath: '/',
  devServer: {
    // 防止控制台报错 localhost:8080无法连接
    host: '0.0.0.0',
    port: 8080,
    https: true
  },
  // vue.config.js
  // ...other vue-cli plugin options...
  pwa: {
    workboxPluginMode: 'InjectManifest',
    workboxOptions: {
      swSrc: 'public/sw.js',
    },
  },
  // 调整内部的 webpack 配置。
  // 查阅 https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-cli/webpack.md
  // 动态生成index页面的cdn引用
  chainWebpack: config => {
    if (isProduction) {
      config.externals({
        'vue': 'Vue',
        'vue-router': 'VueRouter',
        'vuex': 'Vuex',
        'axios': 'axios',
        'muse-ui-message': 'MuseUIMessage',
        'vuetify': 'Vuetify',
        'js-cookie': 'Cookies',
        'sockjs-client': 'SockJS',
        'stompjs': 'Stomp',
        'exif-js': 'EXIF',
      })
      config.plugin('html')
        .tap(args => {
          args[0].cdn = cdn
          return args
        })
    }
  },
}
